import itheima.reggie.ReggieApplication;
import itheima.reggie.entity.User;
import itheima.reggie.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;

@SpringBootTest(classes = ReggieApplication.class)
@Slf4j
public class test {
    @Autowired
    UserService service;
    @Autowired
    TransactionTemplate template;
    @Transactional
    @Test
  public void test (){
        System.out.println("开始测试");
        this.save();
        this.save1();
        log.info("test方法执行成功了!!");
    }
    public void save(){
        User user = new User();
        user.setPhone("13564");
        user.setName("测试事务失效");
        service.save(user);
    }
    @Transactional
    public void save1(){
        Object savePoint = null;
        User user = new User();
        user.setPhone("13564");
        user.setName("测试事务失效3");
        service.save(user);
        int a = 1/0; //抛出异常
    }
    @Bean
    public test createBean(){
        test test = new test();
        log.info("生产testBena");
        return test;
    }
}
